package com.github_dididipapa.mall.product.app;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.github_dididipapa.mall.product.service.SpuInfoService;
import com.github_dididipapa.mall.product.vo.SpuInfoSaveVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import com.github_dididipapa.mall.product.entity.SpuInfoEntity;
import com.github_dididipapa.common.utils.PageUtils;
import com.github_dididipapa.common.utils.R;



/**
 * spu信息
 *
 * @author dididipapa
 * @email not_found@404.com
 * @date 2025-04-26 18:51:11
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
//    @Lazy
//    @Autowired
    private final SpuInfoService spuInfoService;


    /**
     * 列表
     */

    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        params.putIfAbsent("catelogId", "");
        PageUtils page = spuInfoService.queryPageCondition(params);

        return R.ok().put("page", page);
    }

    /**
     * 保存商品
     */
    @PostMapping("/save")
    public R saveSpuInfo(@RequestBody SpuInfoSaveVo spuInfoSaveVo){
        spuInfoService.saveSpuInfoDetail(spuInfoSaveVo);
        
        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:spuinfo:info")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:spuinfo:update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:spuinfo:delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /*
     *上架商品
    */
    @PostMapping("/{spuId}/up")
    public R up(@PathVariable("spuId") Long spuId){
        spuInfoService.up(spuId);

        return R.ok();
    }



}
